# set working directory to obtain seats-votes estimates
setwd("~/_data/sv_estimates")

# load seats-votes estimates for Canada
load("can.RData")

# set working directory for SM graphs
setwd("~/_supportingmaterials_tabfig/")

# generate variable "Conservative" to combine the data from various conservative parties
swing$Conservative <- rep(NA,21)
swing$Conservative[1:15] <- swing$PC[1:15]
swing$Conservative[17] <- swing$REF[17]
swing$Conservative[18] <- swing$CA[18]
swing$Conservative[19:21] <- swing$C[19:21]

################################## SM Figure 1 #################################

# save graph to pdf file (color)
pdf("swrtime_can.pdf")
plot(seq(1945,2007,3),swing[,1],xlim=c(1946,2008.5),ylim=c(0,3),type="b",lwd=2,bty="n",
     cex.lab=1.3,cex.axis=1.3,col="yellow",xlab="Year",ylab="Swing Ratio",xaxt="n", main="Canada")
lines(seq(1945,2007,3), swing[,11],lwd=2,type="b",pch=2,col="red")
axis(1,seq(1945,2010,10),seq(1945,2010,10),cex.axis=1.3)
legend(1986,0.5,pch=c(1,2),cex=1.2,pt.cex=1.5,pt.lwd=2,col=c("yellow","red"),bty="n",
       legend=c("Liberal Party","Conservatives"))
dev.off()

# save graph to pdf file (black and white)
pdf("swrtime_can_bw.pdf")
plot(seq(1945,2007,3),swing[,1],xlim=c(1946,2008.5),ylim=c(0,3),type="b",lwd=2,bty="n",
     cex.lab=1.3,cex.axis=1.3,col="darkgray",xlab="Year",ylab="Swing Ratio",xaxt="n", main="Canada")
lines(seq(1945,2007,3), swing[,11],lwd=2,type="b",pch=2,col="black")
axis(1,seq(1945,2010,10),seq(1945,2010,10),cex.axis=1.3)
legend(1986,0.5,pch=c(1,2),cex=1.2,pt.cex=1.5,pt.lwd=2,col=c("darkgray","black"),bty="n",
       legend=c("Liberal Party","Conservatives"))
dev.off()